import { Message } from 'element-ui';
import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import XuQiu from '../views/XuQiu.vue'
import Brand from '../views/Brand.vue'
import XinXiPiLu from '@/views/XinXiPiLu.vue'
import News from '@/views/News.vue'
import Connection from '@/views/Connection.vue'
import ZhuCe from '@/views/ZhuCe.vue'
import XiuGai from '@/views/XiuGai.vue'
import YanZhengMaLogin from '@/views/YanZhengMaLogin.vue'
import PersonalCenter from '@/views/PersonalCenter.vue'
import ProjectDetails from "@/views/ProjectDetails.vue";
import BrandHomePage from "@/views/BrandHomePage.vue";
import ZhengCe from "@/views/ZhengCe.vue";
import NewsDetail from "@/views/NewsDetail.vue";
import QiyeWeihul from '@/views/QiyeWeihul.vue';
import XuQiuFaBu from '@/views/XuQiuFaBu.vue';
import XiangmuGuanli from '@/views/XiangmuGuanli.vue';
import login from '@/views/Login.vue';
import BrandDetail from '@/views/BrandDetail.vue';
import PersonalNew from '@/views/PersonalNew.vue';
import PersonalNews from '@/views/PersonalNews.vue';
import BrandNesDetail from '@/views/BrandNesDetail.vue'
import Trading from '@/views/Trading.vue';

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView
  },
  {
    path: '/xuqiu',
    name: 'xuqiu ',
    component: XuQiu
  },
  {
    path: '/brand',
    name: 'brand',
    component: Brand,
  },
  {
    path: '/XinXiPiLu',
    name: 'XinXiPiLu',
    component: XinXiPiLu
  },
  {
    path: '/news',
    name: 'news',
    component: News
  },
  {
    path: '/connection',
    name: 'connection',
    component: Connection
  },
  {
    path: '/login',
    name: 'login',
    component: login
  },
  //企业注册
  {
    path: '/ZhuCe',
    name: 'ZhuCe',
    component: ZhuCe
  }
  ,
  // 修改
  {
    path: '/XiuGai',
    name: 'XiuGai',
    component: XiuGai
  },
  {
    path: '/YanZhengMaLogin',
    name: 'YanZhengMaLogin',
    component: YanZhengMaLogin
  },
  // 个人中心
  {
    path: '/PersonalCenter',
    name: 'PersonalCenter',
    component: PersonalCenter,
    children: [
      {
        path: '/qiyeWeihu',
        component: QiyeWeihul,
      }, {
        path: '/xuqiufabu',
        component: XuQiuFaBu
      }, {
        path: '/XiangmuGuanli',
        component: XiangmuGuanli
      },
      {
        path: '/PersonalNew',
        component: PersonalNew
      },
      {
        path: '/PersonalNews',
        component: PersonalNews
      }
    ]
  },
  // 项目详情页
  {
    path: '/ProjectDetails',
    name: 'ProjectDetails',
    component: ProjectDetails
  },
  // 机构主页
  {
    path: '/BrandHomePage',
    name: 'BrandHomePage',
    component: BrandHomePage
  },
  //政策法规
  {
    path: '/ZhengCe',
    name: 'ZhengCe',
    component: ZhengCe
  },
  //新闻详情
  {
    path: '/NewsDetail',
    name: 'NewsDetail',
    component: NewsDetail
  },
  
  //隐私条款
  {
    path: '/BrandDetail',
    name: 'BrandDetail',
    component: BrandDetail
  },
  {
    path: '/BrandNesDetail',
    name: 'BrandNesDetail',
    component: BrandNesDetail
  },{
    path: '/Trading',
    name: 'Trading',
    component: Trading
  }

]

const router = new VueRouter({
  routes
})



export default router
//个人中心导航守卫
router.beforeEach((to, from, next) => {
  let userInfo = JSON.parse(localStorage.getItem('list'));
  if (to.path === '/PersonalCenter' || to.path === '/ProjectDetails' || to.path === '/BrandNesDetail' || to.path === '/xuqiufabu' || to.path === '/BrandNesDetail') {
    if (userInfo != null) {
      next();
    } else {
      Message({
        message: '请登录后操作',
        type: 'warning',
        duration: 500,
        onClose: () => {
            router.push('/login')
        }
    });
      // router.push('/login')
    }
  } else {
    next();
  }
})
// 全局后置守卫
router.afterEach((to, from) => {
  window.scrollTo(0, 0)
})


